package com.daykw.douyin.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.daykw.douyin.model.Result;
import com.daykw.douyin.model.VideoAuth;
import com.daykw.douyin.service.ApiService;
import com.daykw.douyin.utils.Const;

@Controller
@RequestMapping("/vip/adm/dy")
public class ApiAction {
	private static Logger logger = Logger.getLogger(ApiAction.class);

	@Resource
	private ApiService apiService;

	@ResponseBody
	@RequestMapping(value = "/getUserInfoList")
	public Result getArticleByUid(HttpServletRequest request, HttpServletResponse response, String token, Integer limit)
			throws Exception {
		Result ret = new Result();
		try {
			if (limit == null || StringUtils.isEmpty(token)) {
				ret.setResult(Const.FAIL, "参数错误，缺少参数");
				return ret;
			}
			if (limit > 1000) {
				ret.setResult(Const.FAIL, "参数错误，要小于1000");
				return ret;
			}
			if (StringUtils.isNotEmpty(token) && token.equals(Const.AD_TOKEN)) {
				List<VideoAuth> data = apiService.getApiUserDate(100);
				ret.setData(data);
			} else {
				ret.setResult(Const.FAIL, "token 秘钥错误");
			}
		} catch (Exception e) {
			ret.setCode(Const.FAIL_404);
			logger.error("", e);
		}
		return ret;
	}

}
